package com.qy.controller.manage;

import com.github.pagehelper.PageHelper;
import com.qy.base.core.*;
import com.qy.base.utils.DateUtil;
import com.qy.model.Charge;
import com.qy.model.Evaluation;
import com.qy.model.Policy;
import com.qy.model.Unit;
import com.qy.service.ChargeService;
import com.qy.service.EvaluationService;
import com.qy.service.PolicyService;
import com.qy.service.UnitService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zaq on 2018/07/10.
 */
@RestController("Manage-EvaluationController")
@RequestMapping("/manage/evaluation")
public class EvaluationController {
    @Resource
    private EvaluationService evaluationService;

    @Resource
    private PolicyService policyService;

    @Resource
    private UnitService unitService;

    @Resource
    private ChargeService chargeService;

    @PostMapping("/add")
    public Result add(@RequestBody Evaluation evaluation) {
        evaluationService.save(evaluation);
        return ResultGenerator.successResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Evaluation evaluation) {
        evaluationService.update(evaluation);
        return ResultGenerator.successResult();
    }

    @GetMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        Evaluation evaluation = evaluationService.findById(id);
        return ResultGenerator.successResult(evaluation);
    }

    @GetMapping("/list")
    public Result list(PageBean<Evaluation> page) {
        PageHelper.startPage(page.getPageNum(), page.getSize());
        List<Evaluation> list = evaluationService.findAll();
        page.setList(list);
        return ResultGenerator.successResult(page);
    }

    //测评列表
    @GetMapping("/evaluationList")
    public Result evaluationList(PageBean<Map> page,Integer type,String content,Evaluation evaluation){
        String user_name = null;
        String phone = null;
        if (type == 1){
           user_name = content;
        }
        if (type == 2){
            phone = content;
        }
        PageHelper.startPage(page.getPageNum(), page.getSize(),"e.add_time desc");
        List<Map> evList = evaluationService.evaluationList(user_name,phone,evaluation.getPolicy_type(),evaluation.getPolicy_need());
        page.setList(evList);
        return ResultGenerator.successResult(page);
    }

    //测评列表-查看
    @GetMapping("/seeEvaluation")
    public Result seeEvaluation(Integer id){
       Evaluation evaluation = evaluationService.findById(id);
        return ResultGenerator.successResult(evaluation);
    }

}
